<?php

namespace App\Http\Controllers\OA;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Logic\OrderLogic;
use Illuminate\Http\Request;

/**
 * 订单服务
 */
class OrderController extends Controller
{
    public function getOrderDetail(Request $request)
    {
        try{
            $rules = [
                'id'=>'required|exists:orders',
                //'is_company'=>'sometimes|in:0,1'
            ];

            $params = $this->mergeRequest($request);
            $this->verify($params,$rules);
            $data = (new OrderLogic())->getOrderDetail($params);

            ret_json('ok','请求成功',$data);

        }catch (\Exception $e){
             ret_json('err',$e->getMessage());
        }
    }


    /**
     * @param Request $request
     * @desc 获取订单列表
     */
    public function getOrderList(Request $request)
    {
        try{
            $rules = [
                'status'=>'sometimes|in:0,1,2'
            ];

            $params = $this->mergeRequest($request);
            $this->verify($params,$rules);
            $data = (new OrderLogic())->getOrderList($params);

            ret_json('ok','ok',$data);

        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }

    /**
     * @desc 通过xmid获取订单
     */
    public function getOrderByXmid(Request $request)
    {
        try{
            $rules = [
                'xmid'=>'required'
            ];

            $params = $this->mergeRequest($request);
            $this->verify($params,$rules);
            $data = (new OrderLogic())->getOrderByXmid($params);

            ret_json('ok','ok',$data);

        }catch (\Exception $e){
            ret_json('err',$e->getMessage());
        }
    }
}
